package com.demo.interview.a1b2c3;

import java.util.concurrent.locks.LockSupport;

/**
 * @author shenguangyang
 */
public class T03_LockSupport {
    static Thread t1 = null;
    static Thread t2 = null;

    public static void main(String[] args) {
        char[] aI = "ABCDEF".toCharArray();
        char[] aC = "123456".toCharArray();

        t1 = new Thread(() -> {
            for (char c : aI) {
                System.out.print(c);
                LockSupport.unpark(t2); //叫醒T2
                LockSupport.park(); //T1阻塞
            }
        });

        t2 = new Thread(() -> {
            for (char c : aC) {
                LockSupport.park(); //t2阻塞
                System.out.print(c);
                LockSupport.unpark(t1); //叫醒t1
            }
        });

        t1.start();
        t2.start();
    }
}
